//
//  NetworkTools.swift
//  swift-微博
//
//  Created by chenrin on 2016/12/19.
//  Copyright © 2016年 zhuoheng. All rights reserved.
//

import UIKit
import Alamofire

enum MethodType{
    case GET
    case POST
}

class NetworkTools {
   class func requestData(methodType:MethodType,urlString:String,parameters:[String:String]? = nil,finishedCallback : @escaping (_ result:Any) -> ()) {
        //1.获取类型
        let method = methodType == .GET ? HTTPMethod.get : HTTPMethod.post
        //2.发送网络请求
        Alamofire.request(urlString, method: method, parameters: parameters).responseJSON { (response) in
            //3.获取结果
            guard let result = response.result.value else{
                return
            }
            //4.将结果回调出去
            finishedCallback(result:result)
            
        }
    }
}
